<?php
require_once 'modules/content/models/Content.php';
require_once 'modules/content/models/ContentCategory.php';
require_once 'modules/language/models/Lang.php';
class front_main_menuSticker extends Nine_Sticker
{
    public function run()
    {
        $objLang  = new Models_Lang();
        $allLangs = $objLang->getByColumns(array('enabled = ?' => 1), array('sorting ASC'))->toArray();
        $this->view->allLangs = $allLangs;
        $this->view->numLangs = count($allLangs);
//        echo "<pre>";print_r(count($allLangs) );die;
        $objContent = new Models_Content();
        $objCats = new Models_ContentCategory();
        $allCats = $objCats->getAllEnabledCategory();
        $service = $objCats->getAllContentCatWithParent(1,2);
        $reference = $objCats->getAllContentCatWithParent(3,3);
        $partner = $objCats->getAllContentCatWithParent(5,3);
        
        $serviceMenus = array(
                    'url' => Nine_Route::_("content/index/index/cid/1"),
                    'name' => Nine_Language::translate('Service'),
                    'id' => 'service',
                    'childs' => array()
                    );
         $referenceMenus = array(
                    'url' => Nine_Route::_("content/index/index/cid/3"),
                    'name' => Nine_Language::translate('Reference'),
                    'id' => 'reference',
                    'childs' => array()
                    );
         $partnerMenus = array(
                    'url' => Nine_Route::_("content/index/index/cid/5"),
                    'name' => Nine_Language::translate('Partner'),
                    'id' => 'partner'
                    );
        
//         foreach($service as $newsCat) {
                $tmp = array();
//                $tmp['url'] = Nine_Route::_("content/index/index/cid/1");
//                $tmp['name'] = $newsCat['name'];
//                $tmp['id'] = $newsCat['content_category_gid'];
//                $tmp['childs'] = array();
                $condition = array();
                $allChilds = $objContent->getAllEnabledContentByCategory(1, $condition, 
                                                                        array('sorting ASC'));
                if (!empty($allChilds)) {
                    foreach ($allChilds as $item) {
                        $tmp2 = array();
                        $tmp2['url'] = Nine_Route::_("content/index/detail/id/{$item['content_gid']}",array('alias' => $tmp2['alias']));
                        $tmp2['name'] = $item['title'];
                        $tmp2['id'] = $item['content_category_gid'];
                        
                        $tmp[] = $tmp2;
                    }
                }
                
                $serviceMenus['childs'] = $tmp;
                $serviceMenus['url'] = $tmp[0]['url'];
//            }
            
//            echo "<pre>";print_r($serviceMenus);die;
            
    foreach($reference as $newsCat) {
                $tmp = array();
                $tmp['url'] = Nine_Route::_("content/index/index/cid/{$newsCat['content_category_gid']}",array('alias' => $tmp['alias']));
                $tmp['name'] = $newsCat['name'];
                $tmp['id'] = $newsCat['content_category_gid'];
                $tmp['childs'] = array();
                if (!empty($newsCat['child'])) {
                    foreach ($newsCat['child'] as $item) {
                        $tmp2 = array();
                        $tmp2['url'] = Nine_Route::_("content/index/index/cid/{$item['content_category_gid']}",array('alias' => $tmp2['alias']));
                        $tmp2['name'] = $item['name'];
                        $tmp2['id'] = $item['content_category_gid'];
                        $tmp2['childs'] = array();
                        
                        $tmp['childs'][] = $tmp2;
                    }
                }
                
                $referenceMenus['childs'][] = $tmp;
            }
            
    foreach($partner as $newsCat) {
                $tmp = array();
                $tmp['url'] = Nine_Route::_("content/index/index/cid/{$newsCat['content_category_gid']}",array('alias' => $tmp['alias']));
                $tmp['name'] = $newsCat['name'];
                $tmp['id'] = $newsCat['content_category_gid'];
                $tmp['childs'] = array();
                if (!empty($newsCat['child'])) {
                    foreach ($newsCat['child'] as $item) {
                        $tmp2 = array();
                        $tmp2['url'] = Nine_Route::_("content/index/index/cid/{$item['content_category_gid']}",array('alias' => $tmp2['alias']));
                        $tmp2['name'] = $item['name'];
                        $tmp2['id'] = $item['content_category_gid'];
                        $tmp2['childs'] = array();
                        
                        $tmp['childs'][] = $tmp2;
                    }
                }
                
                $partnerMenus['childs'][] = $tmp;
            }
            $menus = array(
            0 => array(
                    'url' => Nine_Registry::getAppBaseUrl(),
                    'name' => Nine_Language::translate('Home'),
                    'id' => 'home'
                    ),
            
            1 => array(
                    'url' => Nine_Route::_("content/index/detail/id/9"),
                    'name' => Nine_Language::translate('About us'),
                    'id' => 'aboutus'
                    ),
            2 => $serviceMenus,
                  
            3 => $referenceMenus,
           
//            4 => array(
//                    'url' => Nine_Route::_("default/index/customer"),
//                    'name' => Nine_Language::translate('Partner'),
//                    'id' => 'partner'
//                    ),
            
            5 => array(
                    'url' => Nine_Route::_("contact/index/index"),
                    'name' => Nine_Language::translate('Contact'),
                    'id' => 'contactus'
                    ),
        );
        

        
        $this->view->menus = $menus;
        /**
         * random number
         */
        $this->view->randomNumber = rand(0, 1000000);
        
           
    }
}